package com.dasoji.ordlist;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.content.Intent;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.NumberPicker;
import android.widget.TextView;
import android.util.Log;
import org.json.*;
import android.widget.* ;
import android.widget.AdapterView.OnItemSelectedListener;



public class SettingsActivity extends Activity {


	Button btnSet ;
	EditText difficultyLevel ;
//	EditText startLetter ;
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings);
        
        btnSet = (Button) findViewById (R.id.set_values);
//	ipText = (EditText) findViewById (R.id.edit_ip);
//	portText = (EditText) findViewById (R.id.edit_port);
	btnSet.setOnClickListener (settingsListner);
//	Spinner spinner_alphabet = (Spinner) findViewById(R.id.spinner_alphabet);
//	ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.alphabets_array, android.R.layout.simple_spinner_item);
//	adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//	spinner_alphabet.setAdapter(adapter);
        Spinner spinner_difficulty = (Spinner) findViewById(R.id.spinner_difficulty);
	ArrayAdapter<CharSequence> diffadapter = ArrayAdapter.createFromResource( this, R.array.difficulty_array, android.R.layout.simple_spinner_item);
	diffadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	spinner_difficulty.setAdapter(diffadapter);
//	spinner_alphabet.setOnItemSelectedListener(new MyOnItemSelectedListener());
	spinner_difficulty.setOnItemSelectedListener(new MyOnItemSelectedListener());
	CheckBox meaning = (CheckBox) findViewById(R.id.check_meaning);
	CheckBox pronouncation = (CheckBox) findViewById(R.id.check_pronounce);


	meaning.setOnClickListener (settingsListner);
	pronouncation.setOnClickListener (settingsListner);
    	}

	public class MyOnItemSelectedListener implements OnItemSelectedListener 
	{

	    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) 
		{	
/*			if (parent.getId()==R.id.spinner_alphabet)
			{
                String alphabet = parent.getItemAtPosition(pos).toString();
                if (alphabet.equals("ALL"))
                    alphabet="";
				Preferences.setAlphabet(alphabet);
				//Toast.makeText(parent.getContext(), "The alphabet is is " + parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
			}*/
			//else if (parent.getId() == R.id.spinner_difficulty)
			if (parent.getId() == R.id.spinner_difficulty)
			{
				Preferences.setDifficulty(Integer.parseInt(parent.getItemAtPosition(pos).toString()));
				//Toast.makeText(parent.getContext(), "The difficulty  is " + parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
			}
		}
	    public void onNothingSelected(AdapterView parent) {
	      // Do nothing.er==
	    }
	}


    
    private OnClickListener settingsListner = new OnClickListener() {
        public void onClick(View v) {
		try
		{
       			if (v.getId()==R.id.set_values)
				launchDictionary();
			else if (v.getId() == R.id.check_meaning)
			{
				Log.v("Setting meaning","Setting meaning");
				if ( ((CheckBox)v).isChecked())
				{
					Preferences.setMeaning(true);
				}
				else
				{

					Preferences.setMeaning(false);
				}
				
		
			}
			else if (v.getId() == R.id.check_pronounce)
			{
				Log.v("Setting pron","Setting pron");
				if ( ((CheckBox)v).isChecked())
				{
					Preferences.setPronounce(true);
				}
				else
				{
					Preferences.setPronounce(true);
				}

			}

		}
		catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		
		}
	}

    } ;
    	protected void launchDictionary()
	{
        	Intent i = new Intent(this, DictionaryActivity.class);
	        startActivity(i);
    	}

}

